package com.zyb.patient.activity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.TextView;

import com.zyb.patient.R;
import com.zyb.patient.util.AppUtils;
import com.zyb.patient.view.AboutCommonDialog;

/***
 * 用户中心
 * @author luoming
 */
public class AboutMeSettingActivity extends BaseActivity implements
		OnClickListener {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		this.setContentView(R.layout.activity_about_me_setting);

		((TextView) findViewById(R.id.head_layout_tv)).setText("设置");
		findViewById(R.id.head_layout_back).setOnClickListener(this);

		findViewById(R.id.setting_layout1).setOnClickListener(this);
		findViewById(R.id.setting_layout2).setOnClickListener(this);
		findViewById(R.id.setting_layout3).setOnClickListener(this);
		findViewById(R.id.setting_layout4).setOnClickListener(this);

		overridePendingTransition(R.anim.enter_righttoleft, R.anim.noanim);
	}

	@Override
	public void onClick(View view) {
		// TODO Auto-generated method stub
		if (view.getId() == R.id.head_layout_back) {
			super.onBackPressed();
		} else if (view.getId() == R.id.setting_layout1) {
			goMyAbout();
		} else if (view.getId() == R.id.setting_layout2) {
			goMyFeedBack();
		} else if (view.getId() == R.id.setting_layout3) {
			goQrCode();
		} else if (view.getId() == R.id.setting_layout4) {
			loginOut();
		}
	}

	private void goMyAbout() {
		Intent it = new Intent(mContext, SettingAboutActivity.class);
		startActivity(it);
	}

	private void goMyFeedBack() {
		Intent it = new Intent(mContext, SettingFeedBackActivity.class);
		startActivity(it);
	}

	private void goQrCode() {
		Intent it = new Intent(mContext, SettingQRCodeActivity.class);
		startActivity(it);
	}

	private void loginOut() {

		AppUtils.showDialog(this, "确定要注销吗?", new OnClickListener() {
			@Override
			public void onClick(View v) {
				AboutCommonDialog dialog = (AboutCommonDialog) v.getTag();
				dialog.dismiss();
				int uid = Integer.parseInt(db.getConfigItem("uid"));
				db.DeleteUserDtoById(uid);
				db.modifyConfigItem("uid", "0");
//				sendBroadcast(new Intent(LeftFragment.COM_UPDATE_USER));
				finish();
				showToast("注销成功");
			}
		}, new OnClickListener() {
			@Override
			public void onClick(View v) {
				AboutCommonDialog dialog = (AboutCommonDialog) v.getTag();
				dialog.dismiss();
			}

		});
	}
}
